package com.info33.platform.common.mvc.vo;

import com.fasterxml.jackson.annotation.JsonView;
import com.info33.platform.common.enums.StatusEnum;
import com.info33.platform.common.mvc.jsonview.object.JsonViewResult;
import lombok.Data;

import java.io.Serializable;

@Data
public class Result<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * 统一异常返回 msg
     */
    public static final String RESULT_ERROR_PUBLIC_MSG = "网络异常，请稍后重试";
    /**
     * 统一异常返回 msg
     */
    public static final String RESULT_ERROR_NO_POWER = "操作失败！原因：权限不足";

    @JsonView(JsonViewResult.class)
    private String status;

    @JsonView(JsonViewResult.class)
    private int code;

    @JsonView(JsonViewResult.class)
    private String message;

    @JsonView(JsonViewResult.class)
    private T data;

    @JsonView(JsonViewResult.class)
    private Long date = System.currentTimeMillis();

    public static <T> Result<T> ok() {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.SUCCESS.getStatus());
        result.setCode(StatusEnum.SUCCESS.getCode());
        result.setMessage(StatusEnum.SUCCESS.getMessage());
        return result;
    }

    public static <T> Result<T> ok(String message) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.SUCCESS.getStatus());
        result.setCode(StatusEnum.SUCCESS.getCode());
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> ok(T data) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.SUCCESS.getStatus());
        result.setCode(StatusEnum.SUCCESS.getCode());
        result.setMessage(StatusEnum.SUCCESS.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> ok(String message, T data) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.SUCCESS.getStatus());
        result.setCode(StatusEnum.SUCCESS.getCode());
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> ok(int code) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.SUCCESS.getStatus());
        result.setCode(code);
        return result;
    }

    public static <T> Result<T> ok(int code, String message) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.SUCCESS.getStatus());
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> ok(int code, String message, T data) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.SUCCESS.getStatus());
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> ok(int code, String message, T data, Long date) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.SUCCESS.getStatus());
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        result.setDate(date);
        return result;
    }

    public static <T> Result<T> error() {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.ERROR.getStatus());
        result.setCode(StatusEnum.ERROR.getCode());
        result.setMessage(StatusEnum.ERROR.getMessage());
        return result;
    }

    public static <T> Result<T> error(int code) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.ERROR.getStatus());
        result.setMessage(StatusEnum.ERROR.getMessage());
        result.setCode(code);
        return result;
    }

    public static <T> Result<T> error(String message) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.ERROR.getStatus());
        result.setCode(StatusEnum.ERROR.getCode());
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> error(T data) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.ERROR.getStatus());
        result.setCode(StatusEnum.ERROR.getCode());
        result.setMessage(StatusEnum.ERROR.getMessage());
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(String message, T data) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.ERROR.getStatus());
        result.setCode(StatusEnum.ERROR.getCode());
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(int code, String message) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.ERROR.getStatus());
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

    public static <T> Result<T> error(int code, String message, T data) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.ERROR.getStatus());
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> error(int code, String message, T data, Long date) {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.ERROR.getStatus());
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        result.setDate(date);
        return result;
    }

    public static <T> Result<T> noCertified() {
        Result<T> result = new Result<>();
        result.setStatus(StatusEnum.NO_CERTIFIED.getStatus());
        result.setCode(StatusEnum.NO_CERTIFIED.getCode());
        result.setMessage(StatusEnum.NO_CERTIFIED.getMessage());
        return result;
    }

}
